home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / TSRDEMO2.ASM < prev    next >
Assembly Source File  |  1987-03-10  |  46KB  |  1,503 lines

  1. page    60,132
  2. ;==============================================================================
  3. ; TSRDEMO2.ASM
  4. ; Thomas Brandenborg
  5. ; 87.02.11
  6. ;
  7. ; Sample demonstration of a safe approach for writing TSR programmes.
  8. ;
  9. ;------------------------------------------------------------------------------
  10. ; Copyright 1987 by Thomas Brandenborg. All Rights Reserved
  11. ; Written for uploading to Compuserve Forums by
  12. ;    Thomas Brandenborg
  13. ;    Lundbyesgade 11
  14. ;    DK-8000 Aarhus C
  15. ;    DENMARK
  16. ;
  17. ; This code is intended as a reference to users on Compuserve Forums
  18. ; on how to write Terminate-And-Stay resident programmes for Personal
  19. ; Cumputers running under DOS versions 2.00 and newer.
  20. ;
  21. ; The code is not part of any proprietary product, but is rather a
  22. ; demonstration of such techniques that may be used to write safe TSR
  23. ; programmes.
  24. ;
  25. ; All or part of it may, however, be used in other software products
  26. ; or otherwise distributed assuming the copyright holders Name & Address
  27. ; as listed above are included clearly and visibly in the documentation
  28. ; for such product.
  29. ;
  30. ; The copyright holder offers no warranty with this code whatsoever,
  31. ; including its fitness for any particular purpose. Neither shall he
  32. ; be liable for damages of any kind that may arise from its use.
  33. ;
  34. ;
  35. ; IF YOU THINK THIS CODE IS USEFUL:
  36. ;
  37. ; If you think this code has had some value to you, and in particular
  38. ; if you consider using all or parts of it in your own product, you
  39. ; may want to consider a smaller or larger donation to the author
  40. ; (Name & Address above) who spend his late night hours putting
  41. ; it together.
  42. ;
  43. ; As to the size of a such donation this is entirely up to your own
  44. ; judgement. It is suggested that you simply consider the value this
  45. ; code has had to you, the time you saved not having to write it your
  46. ; self... that should help you determine the right amount.
  47. ;
  48. ; Please notice that such donations are an entirely voluntary contribution.
  49. ; This holds true whatever your purpose is for using this code, and whatever
  50. ; the type of product and distribution you work with. The author has nothing
  51. ; against commercial software distribution and does not have any reason
  52. ; to restrict developers of commercial products in their use of this code.
  53. ;------------------------------------------------------------------------------
  54. ; COMPILING:    masm tsrdemo2;
  55. ; LINKING:    link tsrdemo2;
  56. ;         exe2bin tsrdemo2 tsrdemo2.com
  57. ;------------------------------------------------------------------------------
  58. ; Revisions
  59. ; Brandenborg 87.02.14    Added copyright notice & checked comments
  60. ; Brandenborg 87.02.17    Added full AX value in Set Ext Err call
  61. ; Brandenborg 87.02.25    Went through to optimize things
  62. ; Brandenborg 87.02.28    Added auto INT28 invocation in INT16 handler
  63. ; Brandenborg 87.03.01    Added INT21 filter for recursion onto console stack
  64. ; Brandenborg 87.03.02    Final cleanup of comments etc.
  65. ; Brandenborg 87.03.10    INT28 handler chains AFTER popup actions
  66. ;            InitPopup: INT21.33 (AL=2) not allowed for DOS 2.x
  67. ;            InitPopup: Set ext err info uses all regs
  68. ;==============================================================================
  69.  
  70. ;==============================================================================
  71. ; DEFINE BIOS DATA SEGMENT OFFSETS
  72. ;==============================================================================
  73.  
  74. BiosData    segment at 40h
  75.         org    17h
  76. KbFlag        label    byte        ;current shift status bits
  77.         org    18h
  78. KbFlag1        label    byte        ;current key status of toggle keys
  79. BiosData    ends
  80.  
  81. ;==============================================================================
  82. ; DEFINE OFFSETS WITHIN BIOS EXTRA DATA SEGMENT
  83. ;==============================================================================
  84.  
  85. BiosXX        segment at 50h
  86.         org    0
  87. StatusByte    label    byte        ;PrtSc status
  88. BiosXX        ends
  89.  
  90. ErrPrtSc    equ    -1        ;err during last PrtSc
  91. InPrtSc        equ    1        ;PrtSc in progress
  92.  
  93. ;==============================================================================
  94. ; DEFINE OFFSETS WITHIN OUR PSP
  95. ;==============================================================================
  96.  
  97. Cseg        segment byte public
  98.         org    2
  99. TopSeg        label    word        ;last seg in alloc block
  100.         org    2ch
  101. EnvSeg        label    word        ;seg of our environment copy
  102. Cseg        ends
  103.  
  104. ;==============================================================================
  105. ; DOS COM-FILE ENTRY POINT
  106. ;==============================================================================
  107.  
  108. Cseg        segment public byte
  109.         assume    cs:Cseg, ds:nothing, es:nothing, ss:nothing
  110.         org    100h
  111. ComEntry:    jmp    Init        ;JMP to init at bottom of seg
  112.  
  113. ;==============================================================================
  114. ; IDENTIFICATION CODES FOR THIS TSR (MUST BE UNIQUE FOR EACH CO-EXISTING TSR)
  115. ; HIGH BYTE OF GetId MUST NOT MATCH ANY AH REQUEST CODES FOR INT16H.
  116. ;==============================================================================
  117.  
  118. GetId        equ    'tc'            ;INT16h AX val to get MyId
  119. MyId        equ    'TC'            ;ID of this TSR
  120.  
  121. ;==============================================================================
  122. ; FLAGS AND PTRS FOR RESIDENT HANDLING
  123. ;==============================================================================
  124.  
  125. TsrMode        db    0            ;bits for various modes
  126. InInt08        equ    1 SHL 0            ;timer0 tick handler
  127. InInt09        equ    1 SHL 1            ;keyboard handler
  128. InInt13        equ    1 SHL 2            ;BIOS disk I/O
  129. InInt28        equ    1 SHL 3            ;INT28 handler
  130. In28Call    equ    1 SHL 4            ;we have issued INT28
  131. InPopup        equ    1 SHL 5            ;popup routine activated
  132. NewDos        equ    1 SHL 6            ;DOS 2.x in use
  133. InDosClr    equ    1 SHL 7            ;InDos=0 at popup time
  134.  
  135. KeyMode        db    0            ;bits for hotkey status
  136. HotIsShift    equ    1 SHL 0            ;hotkey is shift state
  137. InHotMatch    equ    1 SHL 1            ;so far keys match hotkey seq
  138. HotKeyOn    equ    1 SHL 2            ;full hotkey pressed
  139.  
  140. InDosPtr    label    dword            ;seg:off of InDos flag
  141. InDosOff    dw    0
  142. InDosSeg    dw    0
  143.  
  144. CritErrPtr    label    dword            ;seg:off of CritErr flag
  145. CritErrOff    dw    0
  146. CritErrSeg    dw    0
  147.  
  148. ;==============================================================================
  149. ; DATA FOR INT09H HANDLER TO CHECK FOR HOTKEY COMBINATION
  150. ;==============================================================================
  151.  
  152. ; ------------    EQU'S FOR BIT SHIFTS WITHIN KEYBOARD FLAGS
  153.  
  154. InsState    equ    80h
  155. CapsState    equ    40h
  156. NumState    equ    20h
  157. ScrollState    equ    10h
  158. AltShift    equ    08h
  159. CtlShift    equ    04h
  160. LeftShift    equ    02h
  161. RightShift    equ    01h
  162.  
  163. InsShift    equ    80h
  164. CapsShift    equ    40h
  165. NumShift    equ    20h
  166. ScrollShift    equ    10h
  167. HoldState    equ    08h
  168.  
  169. ; ------------    SCAN CODES FOR VARIOUS SHIFT KEYS
  170.  
  171. LeftDown    equ    42            ;scan code of left shift key
  172. LeftUp        equ    LeftDown OR 80h
  173. RightDown    equ    54            ;scan code of right shift key
  174. RightUp        equ    RightDown OR 80h
  175. AltDown        equ    56            ;scan code of alt key
  176. AltUp        equ    AltDown OR 80h
  177. CtlDown        equ    29            ;scan code of ctrl key
  178. CtlUp        equ    CtlDown OR 80h
  179.  
  180. ; ------------    MISC KEYBOARD DATA
  181.  
  182. KbData        equ    60h            ;keyboard data input
  183.  
  184. ;==============================================================================
  185. ; TO USE A SHIFT KEY COMBINATION AS HOT KEY:
  186. ;  -    SET THE FLAG HotIsShift IN KeyMode
  187. ;  -    DEFINE THE SHIFT STATUS BITS IN THE VARIABLE HotKeyShift
  188. ;
  189. ; TO USE A SERIES OF SCAN CODES AS HOT KEY:
  190. ;    CLEAR THE FLAG HotIsShift IN KeyMode
  191. ;  -    INSERT THE MAKE AND BREAK SCAN CODES IN THE HotKeySeq STRING
  192. ;    NOTE:    WITH THIS DEMO IMPLEMENTATION YOU SHOULD NOT USE A HOT KEY
  193. ;        SEQUENCE WHICH PRODUCES A KEY IN THE BIOS KEYBOARD QUEUE,
  194. ;        SINCE THE KEY IS NOT REMOVED BEFORE CALLING THE POPUP ROUTINE.
  195. ;
  196. ; NOTE:    HOTKEY TYPE AND CONTENTS OF HOTKEY VARIABLES MAY BE CHANGED AT RUN TIME
  197. ;==============================================================================
  198.  
  199. HotKeyShift    db    LeftShift OR RightShift    ;shift state IF HotIsShift=FF
  200.  
  201. HotKeySeq    db    LeftDown,LeftUp,LeftDown,LeftUp
  202. HotKeyLen    equ    $-HotKeySeq
  203. HotIndex    db    0            ;# key in seq to compare next
  204. BetweenKeys    db    0            ;timeout count between keys
  205. KeyTimeOut    equ    10            ;more ticks means not a hotkey
  206.  
  207. ;==============================================================================
  208. ; DATA FOR INT08H HANDLER TO CHECK FOR POPUP
  209. ;==============================================================================
  210.